﻿//*** Guidance generated code ***//
using System.Configuration;
using System.Xml;
using System.Xml.Linq;

namespace ProjectBase.Core.Publishing.Configuration
{
    public class ConfigurationSectionHandler : IConfigurationSectionHandler
    {
        public virtual object Create(object parent, object configContext, XmlNode section)
        {
            using (var nodeReader = new XmlNodeReader(section))
            {
                return Create(XDocument.Load(nodeReader).Root);
            }
        }
        public virtual PublishingConfiguration Create(XElement section)
        {
            var config = new PublishingConfiguration();

            if (section.Is())
            {
                var providerElement = section.Element(Constants.ElementProvider);
                if (providerElement.Is())
                {
                    var providerAttr = providerElement.Attribute(Constants.AttributeType);
                    if (providerAttr.Is())
                    {
                        config.ProviderType = providerAttr.Value;
                    }
                    config.Settings = providerElement;
                }
            }
            return config;
        }
    }
}